package org.example.designmodel.forkjoin;

import java.util.Arrays;
import java.util.Random;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.ForkJoinTask;

public class MergeSortTest {

    private static final int MAX = 10;

    private static final int[] nums = new int[MAX];

    public static void main(String[] args) throws Exception {

        Random r = new Random();
        for (int index = 1; index <= MAX; index++) {
            nums[index - 1] = r.nextInt(10);
        }
        for (int num : nums) {
            System.out.print(num + ",");
        }
        System.out.println();

        long beginTime = System.currentTimeMillis();
        ForkJoinPool joinPool = new ForkJoinPool();
        ForkJoinTask<int[]> joinTask = joinPool.submit(new MergeTask(nums));
        int[] result = joinTask.get();
        Arrays.stream(result).forEach(item-> System.out.print(item + ","));
        System.out.println();
        long endTime = System.currentTimeMillis();
        System.out.println("耗时=" + (endTime - beginTime));
    }
}
